package com.juc.future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @Author Zan
 * @Create 2024/5/6 22:33
 * @ClassName: CompletableFutureAPIDemo
 * @Description : TODO 请用一句话描述该类的功能
 */
public class CompletableFutureAPI3Demo {
    public static void main(String[] args) {
        /*CompletableFuture.supplyAsync(() -> {
            return 1;
        }).thenApply(f -> {
            return f + 2;
        }).thenApply(f -> {
            return f + 3;
        }).thenAccept(System.out::println);*/

        // B拿不到A的结果 - 也就是返回值
        System.out.println(CompletableFuture.supplyAsync(() -> "resultA")
                .thenRun(() -> {}).join()); // null

        System.out.println(CompletableFuture.supplyAsync(() -> "resultA")
                .thenAccept(r -> System.out.println(r)).join());

        System.out.println(CompletableFuture.supplyAsync(() -> "resultA")
                .thenApply(r -> r + "resultB").join());
    }
}
